//
//  SRSilenceClockViewController(Additionals).m
//  SportRing
//
//  Created by elwin on 11/12/14.
//  Copyright (c) 2014 HotOne. All rights reserved.
//

#import "SRSilenceClockViewController(Additionals).h"

@interface SRSilenceClockViewController()

@end

@implementation SRSilenceClockViewController(Additionals)

- (NSString *)getTimeFrom:(SRAlarm *)alarm
{
    long hours = [alarm.time longLongValue]/60;
    
    long minutes = [alarm.time longLongValue]%60;
    
    return [NSString stringWithFormat:@"%ld:%.2ld",hours,minutes];
}

- (NSMutableArray *)getCustomWeekDaysFrom:(SRAlarm *)alarm
{
    NSMutableArray *selectedWeek = [[NSMutableArray alloc] init];
    
    if (alarm.monday.boolValue)
    {
        [selectedWeek addObject:@"周一"];
        
    }
    if (alarm.tuesday.boolValue)
    {
        [selectedWeek addObject:@"周二"];
        
    }
    if (alarm.wednesday.boolValue)
    {
        [selectedWeek addObject:@"周三"];
        
    }
    if (alarm.thursday.boolValue)
    {
        [selectedWeek addObject:@"周四"];
        
    }
    if (alarm.friday.boolValue)
    {
        [selectedWeek addObject:@"周五"];
        
    }
    if (alarm.saturday.boolValue)
    {
        [selectedWeek addObject:@"周六"];
        
    }
    if (alarm.sunday.boolValue)
    {
        [selectedWeek addObject:@"周日"];
    }
    
    return selectedWeek;
}

- (void)getAlarmSettingDetailsFromAlarm:(SRAlarm *)alarm alarmType:(CLOCK_RING_TYPE*)ringType alarmTime:(NSString **)alarmTime alarmWeekDays:(NSMutableArray **) weekDays
{
    if (alarm.on.boolValue)
    {
        if (alarm.once.boolValue)
        {
            *ringType = CLOCK_RING_TYPE_ONE_TIME;
            *alarmTime = [self getTimeFrom:alarm];
            *weekDays = [self getCustomWeekDaysFrom:alarm];

        }
        
        else if (!alarm.once.boolValue && alarm.monday.boolValue && alarm.tuesday.boolValue && alarm.wednesday.boolValue && alarm.thursday.boolValue && alarm.friday.boolValue && alarm.saturday.boolValue && alarm.sunday.boolValue)
        {
            *ringType = CLOCK_RING_TYPE_ERERY_DAY;
            *alarmTime = [self getTimeFrom:alarm];
            *weekDays = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"每天"], nil];
        }
        
        else if (!alarm.once.boolValue && alarm.monday.boolValue && alarm.tuesday.boolValue && alarm.wednesday.boolValue && alarm.thursday.boolValue && alarm.friday.boolValue && !alarm.saturday.boolValue && !alarm.sunday.boolValue)
        {
            *ringType = CLOCK_RING_TYPE_MONDAY_TO_FRIDAY;
            *alarmTime = [self getTimeFrom:alarm];
            *weekDays = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"周一至周五"], nil];
        }
        
        else if (!alarm.once.boolValue)
        {
            *ringType = CLOCK_RING_TYPE_CUSTOM;
            *alarmTime = [self getTimeFrom:alarm];
            *weekDays = [self getCustomWeekDaysFrom:alarm];
        }


    }
    
    else if (!alarm.on.boolValue)
    {
        *ringType = CLOCK_RING_TYPE_DEFAULT;
        *alarmTime = [self getTimeFrom:alarm];
        
        if (alarm.once.boolValue && !alarm.monday.boolValue && !alarm.tuesday.boolValue && !alarm.wednesday.boolValue && !alarm.thursday.boolValue && !alarm.friday.boolValue && !alarm.saturday.boolValue && !alarm.sunday.boolValue)
        {
            *weekDays = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"只响一次"], nil];
        }
        
        else if (!alarm.once.boolValue && alarm.monday.boolValue && alarm.tuesday.boolValue && alarm.wednesday.boolValue && alarm.thursday.boolValue && alarm.friday.boolValue && alarm.saturday.boolValue && alarm.sunday.boolValue)
        {
            *weekDays = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"每天"], nil];
        }
        
        else if (!alarm.once.boolValue && alarm.monday.boolValue && alarm.tuesday.boolValue && alarm.wednesday.boolValue && alarm.thursday.boolValue && alarm.friday.boolValue && !alarm.saturday.boolValue && !alarm.sunday.boolValue)
        {

            *weekDays = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"周一至周五"], nil];
        }
        
        else if (!alarm.once.boolValue)
        {
            *weekDays = [self getCustomWeekDaysFrom:alarm];
        }
    }
    
}


@end
